<template>
  <view class="content">
    <block v-if="item">
      <view class="top-img">
        <!-- appliedType: 1 名额添加 -->
        <block v-if="item.appliedType != 1">
          <image :src="this.$store.state.imgBaseUrl + '/join-big-1.png'" v-if="item.userQualification2mVo.status == 0 && item.accountTransferVo && item.accountTransferVo.status == 0"></image>
          <image :src="this.$store.state.imgBaseUrl + '/store-1.png'" v-else-if="item.userQualification2mVo.status == 1 && item.accountTransferVo && item.accountTransferVo.status == 1"></image>
          <image :src="this.$store.state.imgBaseUrl + '/join-big-2.png'" v-else></image>
        </block>
        <block v-else>
          <image :src="this.$store.state.imgBaseUrl + '/join-big-1.png'" v-if="item.userQualification2mVo.status == 0"></image>
          <image :src="this.$store.state.imgBaseUrl + '/store-1.png'" v-else-if="item.userQualification2mVo.status == 1"></image>
          <image :src="this.$store.state.imgBaseUrl + '/join-big-2.png'" v-else></image>
        </block>
      </view>
      <view class="r-text">
        <text v-if="(item.userQualification2mVo.status == 2 || item.userQualification2mVo.status == 3) && (item.accountTransferVo && (item.accountTransferVo.status == 2 || item.accountTransferVo.status == 3))">
          审核失败
        </text>
        <text v-else-if="item.userQualification2mVo.status == 2 || item.userQualification2mVo.status == 3">
          资质{{item.userQualification2mVo.statusName}}
        </text>
        <text v-else-if="item.accountTransferVo && (item.accountTransferVo.status == 2 || item.accountTransferVo.status == 3)">
          财务{{item.accountTransferVo.statusName}}
        </text>
      </view>
      <view class="hint" v-if="item.userQualification2mVo.status == 0 && item.accountTransferVo && item.accountTransferVo.status == 0">
        请耐心等待1-2个工作日，我们会尽快为您审核，请留意您的短信或系统通知！
      </view>
      <view class="hint" v-if="item.status != 0 && item.status != 1">
        <view>{{item.userQualification2mVo.remark}}</view>
        <view v-if="item.appliedType != 1 && item.accountTransferVo">{{item.accountTransferVo.ideaRemark}}</view>
      </view>
      <view class="icon-list" v-if="item">
        <!-- <view class="box over" v-if="item.status == 2 || item.status == 4">
          <image src="../../static/image/join-sm-3.png"></image>
          <view>
            资质认证
          </view>
        </view> -->
        <view class="box" :class="{over: item.userQualification2mVo.status != 0}">
          <image :src="this.$store.state.imgBaseUrl + '/join-sm-2.png'" v-if="item.userQualification2mVo.status == 0"></image>
          <image :src="this.$store.state.imgBaseUrl + '/join-sm-1.png'" v-if="item.userQualification2mVo.status == 1"></image>
          <image :src="this.$store.state.imgBaseUrl + '/join-sm-3.png'" v-if="item.userQualification2mVo.status == 2 || item.userQualification2mVo.status == 3"></image>
          <view>
            资质认证
          </view>
        </view>
        <block v-if="item.appliedType != 1 && item.appliedType != 4">
          <view class="line"></view>
          <!-- <view class="box over" v-if="item.status == 3 || item.status == 5">
            <image src="../../static/image/join-sm-3.png"></image>
            <view>
              费用缴纳
            </view>
          </view> -->
          <view class="box" :class="{over: item.accountTransferVo && item.accountTransferVo.status != 0}">
            <image src="/static/image/join-sm-2.png" v-if="item.accountTransferVo && item.accountTransferVo.status == 0"></image>
            <image src="/static/image/join-sm-1.png" v-if="item.accountTransferVo && item.accountTransferVo.status == 1"></image>
            <image src="/static/image/join-sm-3.png" v-if="item.accountTransferVo && (item.accountTransferVo.status == 2 || item.accountTransferVo.status == 3)"></image>
            <view>
              费用缴纳
            </view>
          </view>
        </block>
      </view>
      <view class="footer" v-if="(item.userQualification2mVo.status != 0 && item.userQualification2mVo.status != 1) || (item.accountTransferVo && item.accountTransferVo.status != 0 && item.accountTransferVo.status != 1)">
        <button v-if="item.userQualification2mVo.status != 0 && item.userQualification2mVo.status != 1" type="primary" :style="{width: (item.accountTransferVo && item.accountTransferVo.status != 0 && item.accountTransferVo.status != 1) ? '45%': '90%'}" class="sub-btn cur" plain="true" @click="draw(1)">资质申请</button>
        
        <button type="primary" v-if="item.accountTransferVo && item.accountTransferVo.status != 0 && item.accountTransferVo.status != 1" :style="{width: (item.userQualification2mVo.status != 0 && item.userQualification2mVo.status != 1) ? '45%': '90%'}" class="sub-btn cur" plain="true" @click="draw(2)">费用缴纳</button>
      </view>
      <view class="footer" v-if="item.status == 1">
        <button type="primary" style="width: 90%;" class="sub-btn cur" plain="true" @click="gotoHome">返回首页</button>
      </view>
    </block>
    <view>
      <uni-fab
        :pattern="pattern"
        :content="content"
        :horizontal="horizontal"
        :direction="direction"
        @trigger="trigger"
      ></uni-fab>
    </view>
  </view>
</template>
<script>
import { reviewQualification, findResult } from '@/service/join/join.service.js'
import uniFab from '@/components/uni-fab/uni-fab.vue';
import { logoutApi } from '@/service/user/user.service.js'
export default {
  components: {uniFab},
  data() {
    return {
      item: null,
      horizontal: 'right',
      direction: 'horizontal',
      pattern: {
        color: '#FFFFFF',
        backgroundColor: 'rgba(0,0,0,0.5)',
        selectedColor: '#007AFF',
        buttonColor:"#434343"
      },
      content: [
        {
          iconPath: '../../static/image/icon/loginout.png', // 图片路径
          text: '安全退出',
          active: false
        }
      ]
    };
  },
  onShow:function() {
    let joinObj = uni.getStorageSync('joinInfo');
    let recomObj = uni.getStorageSync('recomposeDatas');
    if (joinObj) {
      uni.removeStorageSync('joinInfo');
    }
    if (recomObj) {
      uni.removeStorageSync('recomposeDatas');
    }
    this.getInfo();
  },
  methods: {
    trigger(e) {
      if (e.index == 0) { // 退出
        logoutApi({}, res => {
          if (res.status == 0) {
            uni.showToast({
              title: '登出成功！',
              success: () => {
                setTimeout(function () {
                  uni.clearStorageSync();
                  
                }, 2000);
              }
            })
          }
        }, null, {showErrorMsg: true});
      }
    },
    gotoHome () {
      uni.switchTab({
        url: '/pages/index/index'
      })
    },
    getInfo () {
      findResult({}, (res) => {
        if (res.status == 0) {
          if (res.data) { // 已申请过加盟
            this.item = res.data;
            if (res.data.status == 1 && res.data.upgradeRank > 1 || res.data.appliedType == 4) { // 审核成功去首页
              uni.showToast({
                title: '审核已通过！正在跳转首页...',
                icon: 'none',
                duration: 3000,
                mask: true,
                success: () => {
                  setTimeout(() => {
                    uni.switchTab({
                      url: '/pages/index/index'
                    })
                  }, 3000);
                }
              });
            }
            // 付款失败
            if (this.item.accountTransferVo) {
              if (this.item.accountTransferVo.onlinePay == 1 && this.item.accountTransferVo.status == 0 && !this.item.accountTransferVo.transferImages) {
                let type = this.item.userQualification2mVo.joinType == 0 ? 'enterprise' : 'person';
                let datas = {
                  transferImages: this.item.accountTransferVo.transferImages, // 存储凭证信息
                  remark: this.item.accountTransferVo.remark ,// 存储备注
                  joinId: this.item.id ,// 存储加盟id
                }
                uni.setStorage({ // 存储加盟信息
                  key: 'recomposeDatas',
                  data: datas, // 资质信息
                  success: () => {
                    uni.reLaunch({
                      url: '/pages/join/payFail?type='+ type
                    })
                  }
                })
              }
            }
          } else { // 未申请加盟去加盟入住页
            uni.redirectTo({
              url: '/pages/join/index'
            })
          }
        } else {
          uni.showToast({
            title: res.msg,
            icon: 'none'
          });
        }
      })
    },
    draw (statusType) {
      /**
       * statusType: 1=>资质 2=>费用缴纳
      this.item.status: 0待审核 1审核通过
            2资质审核失败 3财务审核失败
            4资质驳回 5财务驳回 6市场财务均驳回
      **/
      let type = this.item.userQualification2mVo.joinType == 0 ? 'enterprise' : 'person';
      this.item.userQualification2mVo['rank'] = this.item.upgradeRank; //存储加盟的等级
      this.item.userQualification2mVo['joinId'] = this.item.id; //存储该商户的加盟id
      this.item.userQualification2mVo['joinStatus'] = this.item.status; //存储申请的状态
      if (this.item.accountTransferVo) {
        this.item.userQualification2mVo['transferImages'] = this.item.accountTransferVo.transferImages; // 上传凭证的图片
        this.item.userQualification2mVo['remark'] = this.item.accountTransferVo.remark; // 上传凭证的图片
      }
      if (statusType == 1) {
        if ((this.item.appliedType == 1 && this.item.status == 2)) { // 名额添加
          uni.navigateTo({
            url: '/pages/join/index'
          })
        } else {
            if (this.item.userQualification2mVo.status == 2 || this.item.userQualification2mVo.status == 3 || this.item.userQualification2mVo.status == 4) {
              this.item.userQualification2mVo['joinStatus'] = 4;
              uni.setStorage({ // 存储加盟信息
                key: 'recomposeDatas',
                data: this.item.userQualification2mVo, // 资质信息
                success: () => {
                  uni.navigateTo({
                    url: '/pages/join/identityAuthen?type=' + type
                  })
                }
              })
            }
          // }
        }
      } else if (statusType == 2) {
        if (this.item.status == 2 || this.item.status == 3) { // 财务审核失败
          uni.setStorage({ // 存储加盟信息
            key: 'recomposeDatas',
            data: this.item.userQualification2mVo, // 资质信息
            success: () => {
              uni.navigateTo({
                url: '/pages/join/index?from="caiwu"'
              })
            }
          })
        } else if (this.item.status == 4 || this.item.status == 5 || this.item.status == 6) { // 财务审核驳回
          // 去支付
          // joinType   加盟类型 enterprise企业 person个人
          uni.setStorage({ // 存储加盟信息
            key: 'recomposeDatas',
            data: this.item.userQualification2mVo, // 资质信息
            success: () => {
              // joinType   加盟类型 enterprise企业 person个人 
              if (type == 'person') {
                uni.navigateTo({
                  url: '/pages/join/joinEntrance?type=' + type + '&isId=1'
                })
              } else {
                uni.navigateTo({
                  url: '/pages/join/joinEntrance?type=' + type + '&isId=1&isLic=1'
                })
              }
            }
          }) 
        }
      }
      // if (this.item.status == 3) { // 财务审核失败
      //   uni.setStorage({ // 存储加盟信息
      //     key: 'recomposeDatas',
      //     data: this.item.userQualification2mVo, // 资质信息
      //     success: () => {
      //       uni.navigateTo({
      //         url: '/pages/join/index?from="caiwu"'
      //       })
      //     }
      //   })
      // } 
      // else if (this.item.userQualification2mVo.status == 2 || this.item.userQualification2mVo.status == 3) {
      //   this.item.userQualification2mVo['joinStatus'] = 4;
      //   uni.setStorage({ // 存储加盟信息
      //     key: 'recomposeDatas',
      //     data: this.item.userQualification2mVo, // 资质信息
      //     success: () => {
      //       uni.navigateTo({
      //         url: '/pages/join/identityAuthen?type=' + type
      //       })
      //     }
      //   })
      // } else if (this.item.status == 4 || this.item.status == 5 || this.item.status == 6) { // 财务审核驳回
      //   // 去支付
      //   // joinType   加盟类型 enterprise企业 person个人
      //   uni.setStorage({ // 存储加盟信息
      //     key: 'recomposeDatas',
      //     data: this.item.userQualification2mVo, // 资质信息
      //     success: () => {
      //       // joinType   加盟类型 enterprise企业 person个人 
      //       if (type == 'person') {
      //         uni.navigateTo({
      //           url: '/pages/join/joinEntrance?type=' + type + '&isId=1'
      //         })
      //       } else {
      //         uni.navigateTo({
      //           url: '/pages/join/joinEntrance?type=' + type + '&isId=1&isLic=1'
      //         })
      //       }
      //     }
      //   }) 
      // }
    }
  }
}
</script>

<style scoped lang="scss">
.content {
  height: 100vh;
  background-color: #FFFFFF;
}
image {
  width: 100%;
  height: 100%;
}
.result {
  padding-top: 40rpx;
  height: 100vh;
  background-color: #FFFFFF;
}
.top-img {
  padding-top: 60rpx;
  image {
    display: block;
    width: 330rpx;
    height: 330rpx;
    margin: 0 auto 30rpx;
  }
}
.r-text {
  text-align: center;
  font-size: 36rpx;
  font-family: PingFang SC;
  font-weight: 500;
  color: #333333;
}
.hint {
  font-size: 30rpx;
  font-family: PingFang SC;
  font-weight: 500;
  color: #999999;
  margin-top: 52rpx;
  text-align: center;
  padding: 0 60rpx;
  line-height: 1.6;
}
.icon-list {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 150rpx;
  .box {
    color: #999999;
    font-size: 29rpx;
    image {
      display: block;
      width: 51rpx;
      height: 51rpx;
      margin: 0 auto 25rpx;
    }
    &.over {
      color: #434343;
    }
  }
  .line {
    width: 87rpx;
    height: 1px;
    background: #E1E1E1;
    margin-left: 18rpx;
    margin-right: 29rpx;
  }
}
.footer {
  width: 100%;
  border-top: 1px solid #E1E1E1;
  padding: 14rpx 0 20rpx;
  background-color: #FFFFFF;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: absolute;
  bottom: 0;
  left: 0;
  .sub-btn {
    height: 70rpx;
    background-color: #636363;
    font-size: 30rpx;
    line-height: 70rpx;
    color: #ADA697;
    border: none;
    &.cur {
      color: #F6DA99;
      background-color: #434343;
    }
  }
}
</style>
